package com.hg.design.structure.composite.biancheng.ex3;

import java.util.ArrayList;

public class Bags implements Articles {
    //名字
    private String name;

    private ArrayList<Articles> bags = new ArrayList<>();

    public Bags(String name) {
        this.name = name;
    }

    public void add (Articles c){
        this.bags.add(c);
    }

    public void remove(Articles c) {
        this.bags.remove(c);
    }

    public Articles getChild(int i) {
        return this.bags.get(i);
    }

    @Override
    public float calculation() {
        float s = 0;
        for (Articles articles : bags){
            s += articles.calculation();
        }
        return s;
    }

    public void show() {
        for (Articles articles : bags){
            articles.show();
        }
        /*for (Object obj:bags) {
            ((Articles)obj).show();
        }*/
    }
}
